<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8">
    <title>Title</title>
  </head>
  <body>
  
  </body>
  <script>
    // 去重
    const arr = [1, 1, 1, 3, 2, 5, 5];
    const arrSet = [...new Set(arr)];
    console.log(arrSet) // [1, 3, 2, 5]
    
    const str = '1113255';
    const arrStr = [...new Set(str)];
    console.log(arrStr) // ['1', '3', '2', '5']
    
    // 并交差集
    const arr1 = new Set([1, 2, 3])
    const arr2 = new Set([4, 3, 2])
    
    const union = new Set([...arr1, ...arr2]);
    console.log(union) // Set(4) {1, 2, 3, 4}
    
    const intersect = new Set([...arr1].filter(item => arr2.has(item)))
    console.log(intersect) // Set(2) {2, 3}
    
    const difference = new Set([...arr1].filter(item => !arr2.has(item)))
    console.log(difference) // Set(1) {1}
    
    // 增删改查（add、has、delete、clear）
    const setObj = new Set();
    setObj.add(1).add(2).add(3).add(3);
    
    console.log(setObj.has(1)); // true
    setObj.delete(1);
    console.log(setObj.has(1)); // false
    
    console.log(setObj.has(2)); // true
    setObj.clear();
    console.log(setObj.has(2)); // false
    
    // 遍历（keys、values、entries、forEach）
    setObj.add(1).add(2).add(3).add(3);
    console.log(setObj.keys()); // SetIterator {1, 2, 3}
    console.log(setObj.values()); // SetIterator {1, 2, 3}
    console.log(setObj.entries()); // SetIterator {1 => 1, 2 => 2, 3 => 3}
  </script>
</html>